package View.Menu;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.Toolkit;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.net.InetAddress;

import javax.imageio.ImageIO;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.JTextPane;

import Controller.Menu.MenuController;
import Utils.TransparentButton;

public class SMenuPanel extends JPanel{
	private BufferedImage imageBackground ;
	private TransparentButton nyanCatButton;
	private TransparentButton naynCatButton;
	private int buttonWidth, buttonHeight;
	private Point nyanPosition;
	private Point naynPosition;
	private JLabel text;
	private JLabel ipText;
	private JLabel yourIP;
	private JTextField ipTextField;
	private MenuController menuController_;
	
	public SMenuPanel(MenuController menuController) {
		setLayout(null);
		//instancing
		menuController_ = menuController;
		buttonHeight = 200; buttonWidth = 200;
		nyanPosition = new Point(400, 250);
		nyanCatButton = new TransparentButton("");
		naynPosition = new Point(180, 100);
		naynCatButton = new TransparentButton("");
		text = new JLabel();
		ipTextField = new JTextField();
		ipText = new JLabel();
		yourIP = new JLabel();
		
		imageBackground = menuController_.getMedia_().imageBackground;
		
		
		
		// sizing
		nyanCatButton.setSize(buttonWidth, buttonHeight);
		naynCatButton.setSize(buttonWidth, buttonHeight);
		text.setSize(500, 28);
		ipText.setSize(200, 25);
		ipTextField.setSize(125, 25);
		yourIP.setSize(250,25);
		
		// pointing 
		nyanCatButton.setLocation(nyanPosition);
		naynCatButton.setLocation(naynPosition);
		text.setLocation(330, 0);
		ipText.setLocation(100,375);
		ipTextField.setLocation(100, 400);
		yourIP.setLocation(100, 350);
		
		// setText
		text.setText("Select Your Side");
		ipText.setText("Enter The oponent IP");
		try {
			InetAddress thisIp =InetAddress.getLocalHost();
			yourIP.setText("Your IP is: "+thisIp.getHostAddress());
			}
			catch(Exception e) {
			e.printStackTrace();
		}
		
		// Graphing
		Font font = new Font("Verdana", Font.BOLD, 28);
		text.setFont(font);
		text.setForeground(Color.RED);
		font = new Font("Verdana", Font.BOLD, 14);
		ipText.setFont(font);
		ipText.setForeground(Color.RED);
		yourIP.setFont(font);
		yourIP.setForeground(Color.RED);
		
		//Adding
		this.add(nyanCatButton);
		this.add(naynCatButton);
		this.add(text);
		this.add(ipText);
		this.add(ipTextField);
		this.add(yourIP);
		
	}



	public void paintComponent(Graphics g){
		super.paintComponent(g);
		g.drawImage(imageBackground, 0, 0, getWidth(), getHeight(), null);
	}
	
	public void addNyancatButtonActionListener(ActionListener nyan){
		nyanCatButton.addActionListener(nyan);
	}
	
	public void addNaynCatButtonActionListener(ActionListener nayn){
		naynCatButton.addActionListener(nayn);
	}
	
	public String getIP(){
		return yourIP.getText();
	}
	
	public String getOponentIP(){
		return ipTextField.getText();
	}

}
